#ifndef prs_Menu_H
#define prs_Menu_H 

#include "prs_Attr.h"
#include "prs_FrmRules.h"
#include "prs_FrmFunc.h"
#include "prs_FrmDict.h"
#include "svl_TCommand.h"
#include "prs_FrmUseTemplate.h"

namespace prs{



struct TRuleMenu : public snt::TRule
{
  TRuleMenu(
    snt::text::TContext &Context,
    svl::TVariant &VParentNode,
   TRuleSetNodeIdOptionally &RSetNodeIdOptionally
  );

private:  
  //
  bool FSetSubMenuId(snt::text::TIdent::TFuncClosureDoEntryParams &Params);
  bool FSetSubMenuCapt(snt::text::TString::TFuncClosureDoEntryParams &Params);
  bool FSetMenuItemId(snt::text::TIdent::TFuncClosureDoEntryParams &Params);
  bool FSetMenuItemCapt(snt::text::TString::TFuncClosureDoEntryParams &Params);
  bool FSetMenu(snt::text::TIdent::TFuncClosureDoEntryParams &Params);
  //
  svl::TVariant &vParentNode;
  snt::TRule  RMenu, RItem;
  snt::TAlter AItem,AItem2,AMenu;
  svl_Except;
};

struct TNodeMenuBase : public TAttrNode, public TFrmDict{
	TNodeMenuBase(): Receiver(this) {}
	virtual void Build( bool mainmenu ) =0;
	TAttrPointer<attrName_Receiver,IBaseReceiver*> Receiver;
};

struct TNodeMenu;
struct TNodeMenuBaseItems : public TNodeArrayT<TNodeMenuBase>
{
};


struct TMessage_MenuCommand;
struct TNodeMenu : public TNodeMenuBase, public svl::TMenuCommand
{
	DECLARE_ClientNode()
    TAttrNodeType<nodeType_Menu> NodeType;
	TAttrId Id;
	TAttrString<attrName_Caption> Caption;
    TAttrNodeArray<attrName_MenuItems,TNodeMenuBaseItems> Items;
	
  

	::HMENU HMenu;

	static TNodeMenu *SearchMenuById( TNode *FromChild, const svl::TString id);

	virtual void TMenuCommand_Execute( int nItem );

    TNodeMenu() : NodeType(this),Id(this),Caption(this),Items(this)/*, Receiver(this)*/, HMenu(NULL) {}
	~TNodeMenu(){ DestroyMenu( HMenu ); }

	virtual void Build( bool mainmenu = true );
private:
	svl_Except;

};

struct TNodeMenuItem : public TNodeMenuBase
{
	DECLARE_ClientNode()
    TAttrNodeType<nodeType_MenuItem> NodeType;
	TAttrId Id;
	TAttrString<attrName_Caption> Caption;
	
	TNodeMenuItem() : NodeType(this),Id(this),Caption(this) {}

	virtual void Build( bool mainmenu = true );
private:
	svl_Except;
};

struct TxMenu;
struct TMessage_MenuCommand : public TMessage_Base
{
  TNodeMenu *Sender;
  svl::TString Item;
  //
  TMessage_MenuCommand() {
    Sender = NULL;
  }

  bool InMenu( TxMenu &V );
  //bool InMenu2( TNodeMenu &V );

  /*TNodeUseTemplate *SearchMenu(
    TNodeUseTemplate &TemplateType
  );
  //
  TNodeUseTemplate *SearchTemplateById(
    TNodeUseTemplate   &TemplateType,
    const svl::TString &TemplateId
  );*/

};


}

#endif